package org.jypj.dev.vo.hxVo;


import com.google.gson.Gson;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class PushMsg<T> {

    private String target_type;   // users 给用户发消息。chatgroups 给群发消息，chatrooms 给聊天室发消息
    // 注意这里需要用数组，数组长度建议不大于20，即使只有
    // 一个用户u1或者群组，也要用数组形式 ['u1']，给用户发
    // 送时数组元素是用户名，给群组发送时数组元素是groupid
    private Set<String> target = new HashSet<>();
    /**
     * "msg":{  //消息内容
     * "type":"cmd",  // 消息类型
     * "action":"server"
     * },
     */
    private Map<String, Object> msg = new HashMap<>(); //消息内容

    private Map<String, Object> ext = new HashMap<>();//推送内容


    public PushMsg() {
        msg.put("type", "cmd");
        msg.put("action", "server");
        this.target_type = "users";
    }

    public PushMsg(PushObject<T> ext) {
        this();
        this.ext.put("push", ext);
    }

    public PushMsg(String target_type, PushObject<T> ext) {
        msg.put("type", "cmd");
        msg.put("action", "server");
        this.target_type = target_type;
        this.ext.put("push", ext);
    }

    public String getTarget_type() {
        return target_type;
    }

    public void setTarget_type(String target_type) {
        this.target_type = target_type;
    }

    public Set<String> getTarget() {
        return target;
    }

    public void setTarget(Set<String> target) {
        this.target = target;
    }

    public Map<String, Object> getMsg() {

        return msg;
    }

    public void setMsg(Map<String, Object> msg) {
        this.msg = msg;
    }

    public Map<String, Object> getExt() {
        return ext;
    }

    public void setExt(Map<String, Object> ext) {
        this.ext = ext;
    }

    @Override
    public String toString() {

        return new Gson().toJson(this);
    }

}
